package org.way.iam.component;

import cn.dev33.satoken.stp.StpInterface;
import org.springframework.stereotype.Component;
import org.way.iam.dto.UserRolePermissionDto;
import org.way.iam.service.ISysRoleService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class PermissionComponent implements StpInterface {

    @Resource
    private ISysRoleService iSysRoleService;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        List<UserRolePermissionDto> rolePermissionList = iSysRoleService.getRolePermission(loginId.toString());
        return rolePermissionList.stream().map(UserRolePermissionDto::getPermissionKey)
                .collect(Collectors.toList());
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<UserRolePermissionDto> userRoleList = iSysRoleService.getUserRole(loginId.toString());
        return userRoleList.stream().map(UserRolePermissionDto::getRoleKey)
                .collect(Collectors.toList());
    }
}
